package com.ruicar.afs.cloud.contract.gateway.processor.value;

import cn.hutool.core.date.DateUtil;
import com.ruicar.afs.cloud.common.util.EmptyUtils;
import com.ruicar.afs.cloud.contract.gateway.enums.ProcessorName;
import org.springframework.stereotype.Component;

/**
 * @author: Lee
 * @date: 2020/5/11 19:39
 * @description:
 */
@Component
public class DateValueConvert implements ValueProcessor<String,String>{
    @Override
    public ProcessorName processName() {
        return ProcessorName.DATA_VALUE_CONVERT;
    }

    @Override
    public String process(String sourceValue, String defaultValue) {
        if(EmptyUtils.isNotEmpty(sourceValue)&&sourceValue.length()>7){
            String yyyy = sourceValue.substring(0, 4);
            String mm = sourceValue.substring(4, 6);
            String dd = sourceValue.substring(6);
            return yyyy+"-"+mm+"-"+dd;
        }
        return sourceValue;
    }
}
